package com.xyht.medicine_management_system.modules.collect.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.collect.entity.req.MmsMedicineCollectAddReq;
import com.xyht.medicine_management_system.modules.collect.entity.req.MmsMedicineCollectDeletedReq;
import com.xyht.medicine_management_system.modules.collect.service.MmsMedicineCollectService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 药品 药资源 收藏 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-11
 */
@RestController
@SecretBody
@RequestMapping("/collect")
public class MmsMedicineCollectController {

    @Resource
    private MmsMedicineCollectService medicineCollectService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("收藏")
    @PostMapping("/add")
    public ResponseResult addCollect(@RequestBody MmsMedicineCollectAddReq addReq, HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return medicineCollectService.addCollect(addReq,userId);
    }

    @ApiModelProperty("删除收藏")
    @PostMapping("/deleted")
    public ResponseResult deletedCollect(@RequestBody MmsMedicineCollectDeletedReq deletedReq){
        return medicineCollectService.deletedCollect(deletedReq);
    }

    @ApiModelProperty("查看列表")
    @GetMapping("/list")
    public ResponseResult getCollectList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "type") Integer type,
                                         HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return medicineCollectService.getCollectList(pageNum,pageSize,userId,type);
    }

}

